﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Collections;
using System.Configuration;
using System.IO;
using FindIt.DAL;
using MySql.Data.MySqlClient;

namespace FindIt.BLL
{
    public class RestrictedWord
    {
        private static HashSet<string> stopWords = GetRestrictedWordsByType("stop");
        private static HashSet<string> noiseWords = GetRestrictedWordsByType("noise");

        private static HashSet<string> GetRestrictedWordsByType(string type)
        {
            HashSet<string> restrictedWords = new HashSet<string>();
            
            string tableName;
            
            if (type == "stop")
                tableName = ConfigurationManager.AppSettings["stopWordTableName"];
            else
                tableName = ConfigurationManager.AppSettings["noiseWordTableName"];

            RestrictedWordDB db = new RestrictedWordDB();
            MySqlDataReader dr = db.GetRestrictedWordsByTableName(tableName);
            
            while (dr.Read())
            {
                restrictedWords.Add(dr[0].ToString());
            }

            dr.Close();

            return restrictedWords;
        }

        public static bool IsStopWord(string word)
        {
            if (stopWords.Contains(word))
                return true;
            else
                return false;
        }

        public static bool IsNoiseWord(string word)
        {
            if (noiseWords.Contains(word))
                return true;
            else
                return false;
        }
    }
}